home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / efs / dired-diff.el.z / dired-diff.el
Encoding:
Text File  |  1998-05-21  |  5.4 KB  |  165 lines

  1. ;; -*-Emacs-Lisp-*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;
  4. ;; File:           dired-diff.el
  5. ;; RCS:
  6. ;; Dired Version:  #Revision: 7.9 $
  7. ;; Description:    Support for diff and related commands.
  8. ;; Author:         Sandy Rutherford <sandy@ibm550.sissa.it>
  9. ;; Created:        Fri Jun 24 08:50:20 1994 by sandy on ibm550
  10. ;; 
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. ;;; This program is free software; you can redistribute it and/or modify
  14. ;;; it under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 1, or (at your option)
  16. ;;; any later version.
  17. ;;;
  18. ;;; This program is distributed in the hope that it will be useful,
  19. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; A copy of the GNU General Public License can be obtained from this
  24. ;;; program's author (send electronic mail to sandy@ibm550.sissa.it) or
  25. ;;; from the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
  26. ;;; MA 02139, USA.
  27.  
  28. (provide 'dired-diff)
  29. (require 'dired)
  30.  
  31. (defvar emerge-last-dir-input)
  32. (defvar emerge-last-dir-output)
  33. (defvar emerge-last-dir-ancestor)
  34. (defvar diff-switches)
  35.  
  36. (defun dired-diff-read-file-name (prompt)
  37.   ;; Read and return a file name for diff.
  38.   (let* ((mark-active t)
  39.      (default (and (mark)
  40.                (save-excursion
  41.              (goto-char (mark))
  42.              (dired-get-filename nil t)))))
  43.     (read-file-name (format "%s %s with: %s"
  44.                 prompt (dired-get-filename 'no-dir)
  45.                 (if default
  46.                 (concat "["
  47.                     (dired-make-relative
  48.                      default
  49.                      (dired-current-directory) t)
  50.                     "] ")
  51.                   ""))
  52.             (default-directory) default t)))
  53.  
  54. (defun dired-diff-read-switches (switchprompt)
  55.   ;; Read and return a list of switches
  56.   (or (boundp 'diff-switches)
  57.       (require 'diff)) ; Make sure that `diff-switches' is defined.
  58.   (let* ((default (if (listp diff-switches)
  59.               (mapconcat 'identity diff-switches " ")
  60.             diff-switches))
  61.      (switches
  62.       (read-string (format switchprompt default) default)))
  63.     (let (result (start 0))
  64.       (while (string-match "\\(\\S-+\\)" switches start)
  65.     (setq result (cons (substring switches (match-beginning 1)
  66.                       (match-end 1))
  67.                result)
  68.           start (match-end 0)))
  69.       (nreverse result))))
  70.  
  71. (defun dired-diff (file &optional switches)
  72.   "Compare file at point with file FILE using `diff'.
  73. FILE defaults to the file at the mark.
  74. The prompted-for file is the first file given to `diff'.
  75. With a prefix allows the switches for the diff program to be edited."
  76.   (interactive
  77.    (list
  78.     (dired-diff-read-file-name "Diff") 
  79.     (and current-prefix-arg (dired-diff-read-switches "Options for diff: "))))
  80.   (if switches
  81.       (diff file (dired-get-filename) switches)
  82.     (diff file (dired-get-filename))))
  83.  
  84. (defun dired-backup-diff (&optional switches)
  85.   "Diff this file with its backup file or vice versa.
  86. Uses the latest backup, if there are several numerical backups.
  87. If this file is a backup, diff it with its original.
  88. The backup file is the first file given to `diff'."
  89.   (interactive (list (and current-prefix-arg
  90.               (dired-diff-read-switches "Diff with switches: "))))
  91.   (if switches
  92.       (diff-backup (dired-get-filename) switches)
  93.     (diff-backup (dired-get-filename))))
  94.  
  95. (defun dired-emerge (arg file out-file)
  96.   "Merge file at point with FILE using `emerge'.
  97. FILE defaults to the file at the mark."
  98.   (interactive
  99.    (let ((file (dired-diff-read-file-name "Merge")))
  100.      (list
  101.       current-prefix-arg
  102.       file
  103.       (and current-prefix-arg (emerge-read-file-name
  104.                    "Output file"
  105.                    emerge-last-dir-output
  106.                    (dired-abbreviate-file-name file) file)))))
  107.   (emerge-files arg file (dired-get-filename) out-file))
  108.  
  109. (defun dired-emerge-with-ancestor (arg file ancestor file-out)
  110.   "Merge file at point with FILE, using a common ANCESTOR file.
  111. FILE defaults to the file at the mark."
  112.   (interactive
  113.    (let ((file (dired-diff-read-file-name "Merge")))
  114.      (list
  115.       current-prefix-arg
  116.       file
  117.       (emerge-read-file-name "Ancestor file" emerge-last-dir-ancestor nil file)
  118.       (and current-prefix-arg (emerge-read-file-name
  119.                    "Output file"
  120.                    emerge-last-dir-output
  121.                    (dired-abbreviate-file-name file) file)))))
  122.   (emerge-files-with-ancestor arg file (dired-get-filename)
  123.                   ancestor file-out))
  124.  
  125. (defun dired-ediff (file)
  126.   "Ediff file at point with FILE.
  127. FILE defaults to the file at the mark."
  128.   (interactive (list (dired-diff-read-file-name "Ediff")))
  129.   (ediff-files file (dired-get-filename)))
  130.  
  131. (defun dired-epatch (file)
  132.   "Patch file at point using `epatch'."
  133.   (interactive
  134.    (let ((file (dired-get-filename)))
  135.      (list
  136.       (and (or (memq 'patch dired-no-confirm)
  137.            (y-or-n-p (format "Patch %s? "
  138.                 (file-name-nondirectory file))))
  139.        file))))
  140.   (if file
  141.       (ediff-patch-file file)
  142.     (message "No file patched.")))
  143.  
  144. ;;; Autoloads
  145.  
  146. ;;; Diff (diff)
  147.  
  148. (autoload 'diff "diff" "Diff two files." t)
  149. (autoload 'diff-backup "diff"
  150.       "Diff this file with its backup or vice versa." t)
  151.  
  152. ;;; Emerge
  153.  
  154. (autoload 'emerge-files "emerge" "Merge two files." t)
  155. (autoload 'emerge-files-with-ancestor "emerge"
  156.      "Merge two files having a common ancestor." t)
  157. (autoload 'emerge-read-file-name "emerge")
  158.  
  159. ;; Ediff
  160.  
  161. (autoload 'ediff-files "ediff" "Ediff two files." t)
  162. (autoload 'ediff-patch-file "ediff" "Patch a file." t)
  163.  
  164. ;;; end of dired-diff.el
  165.